<template>
  <div class="module">
    <!--告警频次分析-->
    <MTitle ref="title" icon="gjpcfx" @search="search"></MTitle>
    <MBox>
<!--      <MTabs :list="list" :activeIndex="activeIndex" @change="tabChange"></MTabs>-->
      <div class="content-wrapper">
        <div class="content">
          <ScrollList :data="dataList" :column="column" empty-text="安全生产，人人有责。"></ScrollList>
        </div>
      </div>
    </MBox>
  </div>
</template>

<script>
import MTitle from '../base-com/m-title/m-title'
import MBox from '../base-com/m-box/m-box'
import MTabs from '../base-com/m-tabs/m-tabs'
import ScrollList from '../base-com/scroll-list/scroll-list'
import { warningFrequencyStatistics } from '@/api/warnings'
import { shipMixin } from '../../mixins/mixin'

export default {
  mixins: [shipMixin],
  components: {
    MTitle,
    MBox,
    MTabs,
    ScrollList
  },
  data() {
    return {
      time: 10,
      activeIndex: 1,
      list: [
        {
          name: '频次分析(日)',
          value: "1",
        },
        {
          name: '频次分析(月)',
          value: "5",
        },
        {
          name: '频次分析(指定)',
          value: "0",
        },
      ],
      dataList: [],
      column: [
        {type: 'index'},
        {prop: 'name'},
        {prop: 'count'},
      ]
    }
  },
  methods: {
    shipChange() {
      this.tabChange(this.activeIndex)
    },
    initData() {
      const searchData = this.$refs.title.getForm()
      let params = {}
      if (this.activeIndex !== 2) {
        params = {
          timeType: this.list[this.activeIndex].value
        }
      } else {
        params = {...searchData}
      }
      params.shipId = this.shipId
      warningFrequencyStatistics(params).then(res => {
        this.dataList = res.result || []
      })
    },
    tabChange(index) {
      this.activeIndex = index
      if (index < 2) {
        this.$refs.title.$refs.timeFilter.selectChange(this.list[this.activeIndex].value)
      } else {
        this.initData()
      }
    },
    search(form) {
      if (form.timeType === this.list[0].value) {
        this.activeIndex = 0
      } else if (form.timeType === this.list[1].value) {
        this.activeIndex = 1
      } else if (this.list[this.activeIndex].value !== form.timeType) {
        this.activeIndex = 2
      }
      this.initData()
    }
  }
}
</script>

<style scoped lang="scss">
.content-wrapper {
  flex: 1;
  position: relative;
  .content {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    padding: 20px 15px;
  }
}
</style>
